package aom.ju.ss.view.base;

import android.os.Bundle;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import aom.ju.ss.lpInterface.MyHttpCallBack;
import aom.ju.ss.utils.LogUtils;


public abstract class BaseFragment extends Fragment implements View.OnClickListener, MyHttpCallBack {

    protected ViewDataBinding viewBinding;
    protected FragmentActivity activity;

    @Subscribe
    public void callBack(Message event) {

    }

    public BaseFragment() {
    }

    @Override
    public void ok(String jsonString, String httpTY) {

    }

    @Override
    public void error(String e, String jsonString, String httpTY) {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }

        if (viewBinding == null) {
            viewBinding = DataBindingUtil.inflate(inflater, getLay(), container, false);
            activity = getActivity();


//            try {
                init();
//            }catch (Exception we){
//                LogUtils.e(we.getMessage());
//            }

        }
        onCreateViewInit();
        return viewBinding.getRoot();
    }

    protected void onCreateViewInit() {
    }


    protected abstract void init();

    protected abstract int getLay();

    @Override
    public void onClick(View v) {

    }
}
